window.onload = function () {
    new Vue({
        el: '#vue_block',
        data: {
            author: {
                name: '陈宗豪 201592452 软日1505'
            },
            page: {
                name: 'index',
                state:'complete'
            },
            event_list:[
                {text:'2017-11-12 OpenMRS前端项目正式启动'},
                {text:'2017-11- 3 正在准备小站的多语言版本'},
                {text:'2017-11- 2 和けんちゃん组队，答应小黎做网页'},
                {text:'2017-10-23 网站审核通过'},
                {text:'2017-10-22 当选团支书、优秀团员'}
            ],
            lang:{

                title:'三月十四   陈宗豪的小站',
                subtitle:{
                    1:'代码仓库',
                    2:'编译原理实验列表',
                    3:'代码',
                    4:'大事纪',
                    5:'目录',
                    6:'友情链接'
                },
                noun:{
                    1:'实验',
                    2:'加载中',
                    3:'返回首页',
                    4:'返回顶部',
                }
            }
        },
        methods: {
            lan:function(lang){
                switch (lang){


                    case 'zh-tw':
                        this.lang={
                            title:'三月十四   陳宗豪的小站',
                            subtitle:{
                                1:'代碼倉庫',
                                2:'編譯原理實驗列表',
                                3:'代碼',
                                4:'大事紀',
                                5:'目錄',
                                6:'友情連結'
                            },
                            noun:{
                                1:'實驗',
                                2:'載入中',
                                3:'返回首頁',
                                4:'返回頂部',
                            }
                        };


                        break;
                    case 'jp':
                        this.lang={
                            title:'三月十四   陳宗豪のホームページ',
                            subtitle:{
                                1:'コード倉庫',
                                2:'コンパイラ原理の実験',
                                3:'コード',
                                4:'日記',
                                5:'インデックス',
                                6:'リンク先'
                            },
                            noun:{
                                1:'実験',
                                2:'ロード中',
                                3:'HPへ戻る',
                                4:'TOPへ戻る'
                            }
                        };
                        break;
                    case 'en':
                        this.lang={
                            title:'Mar. 14th   The Website of CHZH',
                            subtitle:{
                                1:'CodeBase',
                                2:'Test of Compiling',
                                3:'Code',
                                4:'Memory',
                                5:'Index',
                                6:'Link'
                            },
                            noun:{
                                1:'Test',
                                2:'Loading',
                                3:'Homepage',
                                4:'Top'
                            }
                        };
                        break;

                    case 'zh-cn':
                    default:
                        this.lang={
                            title:'三月十四   陈宗豪的小站',
                            subtitle:{
                                1:'代码仓库',
                                2:'编译原理实验列表',
                                3:'代码',
                                4:'大事纪',
                                5:'目录',
                                6:'友情链接'
                            },
                            noun:{
                                1:'实验',
                                2:'加载中',
                                3:'返回首页',
                                4:'返回顶部',
                            }
                        }
                }
            },
            router_index: function () {
                this.page.name = "index";

            },
            router_hd00:function(){
                this.page.name = "hd00";
            },
            router_hd01:function(){
                this.page.name = "hd01";
            },
            router_hd02:function(){
                this.page.name = "hd02";
            },
            router_hd03:function(){
                this.page.name = "hd03";
            },
            router_hd04:function(){
                this.page.name = "hd04";
            },
            router_hd05:function(){
                this.page.name = "hd05";
            },
            router_hd06:function(){
                this.page.name = "hd06";
            },
            router_r(index){
                this.page.name = 'r'+index;
            },
            router_test:function(num){
                if(num<10){
                    this.page.name="test0"+num;
                }else{
                    this.page.name="test"+num;
                }
            },
            router_test01: function () {
                // $("#code_test01").reset();
                this.page.name = "test01";

            },
            router_test02: function () {
                // $("#code_test02").css("display:block");
                this.page.name = "test02";
            },
            router_test03: function() {
                this.page.name = "test03";
            },
            router_test03_2:function(){
                this.page.name="test03_2";
            },
            deal_test01:function(event){
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13') {
                    var input_text = $("#input_test01").val();
                    $.ajax({
                        url:"/test/01",
                        type:"post",
                        data:"[\""+input_text+"\"]",
                        contentType:"application/json;charset=utf-8",
                        dataType:'json',
                        success:function (table) {
                            var display = "";
                            console.log(table);
                            for (var i = 0; i < table.length; i += 2) {
                                display += "(" + table[i] + "," + table[i + 1] + ")";
                            }
                            $("#output").text(display);
                        }
                    })

                }
            },
            deal_test02: function () {
                var input_text = $('#input_test02').val();
                console.log(input_text);
                var split_text = input_text.split("\n");
                $.ajax({
                    url: "/test/02",
                    type: "post",
                    data: JSON.stringify(split_text),
                    contentType: "application/json;charset=utf-8",
                    dataType: 'json',
                    success: function (data) {
                        var display = "";
                        for (var i in data) {
                            display += "<p>" + i + ":";
                            for (var j in data[i]) {
                                if (data[i][j] && data[i][j] != "" && data[i][j] != null) {
                                    display += data[i][j] + ",";
                                }
                            }
                            display = display.substring(0, display.length - 1);
                            display += "</p>";
                        }
                        $('#output').html(display);
                    }

                })
            },
            deal_test03:function(event){
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13') {
                    var input_text = $("#input_test03").val();
                    $.ajax({
                        url:"/test/03",
                        type:"post",
                        data:"[\""+input_text+"\"]",
                        contentType:"application/json;charset=utf-8",
                        dataType:'json',
                        success:function (table) {
                            var display = "";
                            console.log(table);
                            for (var i = 0; i < table.length; i += 2) {
                                display += "<p>" + table[i] + "->" + table[i + 1] + "</p>";
                            }
                            $("#output").html(display);
                        }
                    })

                }
            },
            deal_test03_2:function(event){
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13') {
                    var input_text = $("#input_test03_2").val();
                    $.ajax({
                        url:"/test/03_2",
                        type:"post",
                        data:"[\""+input_text+"\"]",
                        contentType:"application/json;charset=utf-8",
                        dataType:'json',
                        success:function (table) {
                            var display = "";
                            console.log(table);
                            for (var i = 0; i < table.length; i ++) {
                                display += "<p>" + table[i] + "</p>";
                            }
                            $("#output").html(display);
                        }
                    })

                }
            },
            deal_test04:function(event){
                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13') {
                    var input_text = $("#input_test04").val();
                    $.ajax({
                        url:"/test/04",
                        type:"post",
                        data:"[\""+input_text+"\"]",
                        contentType:"application/json;charset=utf-8",
                        dataType:'json',
                        success:function (table) {
                            var display = "";
                            console.log(table);
                            for (var i = 0; i < table.length; i ++) {
                                display += "<p>" + table[i] + "</p>";
                            }
                            $("#output").html(display);
                        }
                    })

                }
            }

        }
    })
};